package cn.itcast.n3;/**
 * @author yd
 * @date 2022/3/15 19:29
 * @version 1.0
 */

import lombok.extern.slf4j.Slf4j;

@Slf4j(topic = "w.TestState")
public class TestState {

    public static void main(String[] args) {
        Thread t1 = new Thread("t1") {
            @Override
            public void run() {
                log.debug("running....");
            }
        };
        Thread t2 = new Thread("t2") {
            @Override
            public void run() {
                while(true){

                }
            }
        };
        t2.start();
        Thread t3 = new Thread("t3") {
            @Override
            public void run() {
                log.debug("running....");
            }
        };
        t3.start();

        Thread t4 = new Thread("t4") {
            @Override
            public void run() {
                synchronized (TestState.class){
                    try {
                        Thread.sleep(1000000); //time_waiting
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        t4.start();

        Thread t5 = new Thread("t5") {
            @Override
            public void run() {

                    try {
                       t2.join(); //waiting
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

            }
        };
        t5.start();
        Thread t6 = new Thread("t6") {
            @Override
            public void run() {
                synchronized (TestState.class){
                    try {
                        Thread.sleep(1000000); //time_waiting
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        t6.start();

        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        log.debug("t1 State {}", t1.getState());
        log.debug("t2 State {}", t2.getState());
        log.debug("t3 State {}", t3.getState());
        log.debug("t4 State {}", t4.getState());
        log.debug("t5 State {}", t5.getState());
        log.debug("t6 State {}", t6.getState());

    }


}
